﻿$(document).ready(function () {
    page.init();
});

var page = {
    url: "/handler/auction.ashx?action=",
    pageIndex: 0,
    pageSize: 10,

    init: function () {
        $(".top-bar .right li:eq(2)").addClass("current");
        page.history();
    },

    history: function (pageIndex) {
        if (pageIndex != undefined)
            page.pageIndex = pageIndex;
        $.get(page.url + "history", { pageIndex: page.pageIndex, pageSize: page.pageSize, r: Math.random() }, function (data) {
            $("#result").html(TrimPath.processDOMTemplate("auctionlist", data));
            page.pager(data.count);
        }, "json");
    },

    pager: function (count) {
        if (count == 0) {
            $("#pagination").empty();
            return;
        }
        $("#pagination").pagination(count, {
            num_edge_entries: 2,
            num_display_entries: 10,
            current_page: page.pageIndex,
            items_per_page: page.pageSize,
            callback: page.history
        });
    },

    showAuction: function (auctionId) {
        window.open("AuctionDetail.aspx?id=" + auctionId);
    }
};

